/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.domain;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.customer.facade.enums.CustomerRegisterMethod;
import info.peigen.hotpot.business.customer.facade.enums.CustomerSource;
import info.peigen.hotpot.common.core.domain.DomainObject;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import static info.peigen.hotpot.business.customer.facade.enums.CustomerRegisterMethod.SALES;
import static info.peigen.hotpot.business.customer.facade.enums.CustomerRegisterMethod.SELF;

/**
 * <b>(CustomerMarketing)</b>
 * 客户的与市场营销相关的信息
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CustomerMarketing extends DomainObject {
    /** 注册方式 */
    @Builder.Default
    CustomerRegisterMethod customerRegisterMethod = SELF;
    /** 邀请码 */
    String         inviteCode;
    /** 代理商 */
    String         proxyId;
    /** 销售 */
    String         salesId;
    /** 客服 */
    String         customerServiceId;
    /** 来源 */
    CustomerSource source;

    public void init(String inviteCode) {
        if (StrUtil.isNotBlank(inviteCode)) {
            setInviteCode(inviteCode).setCustomerRegisterMethod(SALES);
        } else {
            setCustomerRegisterMethod(SELF);
        }
    }

    public void check() {
        switch (customerRegisterMethod) {
            case SELF:
                Assert.isTrue(StrUtil.isBlank(inviteCode), "自主注册邀请码为空!");
                Assert.isTrue(StrUtil.isBlank(proxyId), "自主注册代理商为空!");
                Assert.isTrue(StrUtil.isBlank(salesId), "自主注册销售为空!");
                break;
            case SALES:
                Assert.isTrue(StrUtil.isNotBlank(inviteCode), "销售邀请码不得为空!");
                break;
            default:
                break;
        }
    }
}
